﻿using DFGK.IService;
using DFGK.Repository;
using DFGK_WMS.Common;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;

namespace DFGK_WMS.WebAPI.Controllers.权限管理
{
    /// <summary>
    /// 按钮
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [ApiExplorerSettings(GroupName = "RBAC")]
    public class ActionController : BaseController
    {
        private readonly IActionService actionService;

        public ActionController(IWebHostEnvironment environment, IActionService actionService) : base(environment)
        {
            this.actionService = actionService;
        }

        /// <summary>
        /// 显示按钮列表
        /// </summary>
        /// <param name="aname"></param>
        /// <param name="status"></param>
        /// <param name="pageIndex"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetActionList(string? aname = "", int status = 2, int pageIndex = 1, int pageSize = 10)
        {
            if (pageIndex <= 0 || pageSize <= 0)
            {
                return Ok(BaseResult.Result("400", "分页条件有误！"));
            }
            int totalCount;
            var list = actionService.GetActionList(aname, status, pageIndex, pageSize, out totalCount);

            if (list != null)
            {
                return Ok(BaseResult.Result(list, "获取成功", "200", totalCount));
            }
            return Ok(BaseResult.Result(null, "获取失败", "200", 0));
        }

        /// <summary>
        /// 左侧穿梭框显示
        /// </summary>
        /// <param name="mid"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetLeftMenuActionList(long mid = 0)
        {
            var list = actionService.GetLeftMenuActionList(mid);
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "获取成功", "200"));
            }
            return Ok(BaseResult.Result(null, "获取失败", "500"));
        }

        /// <summary>
        /// 右侧穿梭框显示
        /// </summary>
        /// <param name="mid"></param>
        /// <returns></returns>
        [HttpGet]
        public IActionResult GetRightMenuActionList(long mid = 0)
        {
            var list = actionService.GetRightMenuActionList(mid);
            if (list != null)
            {
                return Ok(BaseResult.Result(list, "获取成功", "200"));
            }
            return Ok(BaseResult.Result(null, "获取失败", "500"));
        }
    }
}
